package com.statistics.tools;

import com.alibaba.fastjson.JSONObject;
import com.statistics.bean.Environment;
import com.statistics.bean.EnvironmentTower;
import org.slf4j.LoggerFactory;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.List;

/**
 * @author MeowParse
 * @date 2017/8/18.
 */
public class Tools {

	private static final org.slf4j.Logger logger = LoggerFactory.getLogger(Tools.class);
	private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");


	//{"macoffset ":"1112","total_electricity":"1","max_current":"2","max_power":"3",
	//"statistics_time":"2017-09-01"},{" macoffset ":"11212","total_electricity":"1","max_current":"2",
	//"max_power":"3","statistics_time":"2017-09-01"},{" macoffset ":"11213","total_electricity":"1",
	//"max_current":"2","max_power":"3","statistics_time":"2017-09-01"}
	public static JSONObject getJsonEleStr(String mac, int offset, BigDecimal total_electricity,
                                    BigDecimal max_current, BigDecimal max_power, Long start_date){

		JSONObject json = new JSONObject();
		json.put("macoffset",mac+"_"+offset);
		json.put("total_electricity",total_electricity.setScale(4,BigDecimal.ROUND_DOWN));
		json.put("max_current",max_current.setScale(4,BigDecimal.ROUND_DOWN));
		json.put("max_power",max_power.setScale(4,BigDecimal.ROUND_DOWN));
		json.put("statistics_time",simpleDateFormat.format(start_date));
		return json;
	}

	public static JSONObject getJsonWaterStr(String mac, int offset, BigDecimal totalWater,
	                                        Long start_date){

		JSONObject json = new JSONObject();
		json.put("macoffset",mac+"_"+offset);
		json.put("total_water",totalWater);
		json.put("statistics_time",simpleDateFormat.format(start_date));
		return json;
	}

	public static void sendTo61(String type,String jsonStr){

//		if(jsonStr == null){
//			logger.info("空的JSONARRAY");
//			return;
//		}
//
//		String param = "pageparm="+type+"&Sysuid="+Constants.SYSUID+"&Sysupass="+Constants.SYSUPASS
//				+"&Jsonstr="+jsonStr;
//
//		String result = HttpClient.sendPost(Constants.URL61,param);
//
//		logger.info("URL :{}",Constants.URL61+"?"+param);
//		logger.info("get Result From 61School :{}",result);

	}


	public static JSONObject getJsonEnvStr(String mac, Environment environment, Long start_date) {
		JSONObject json = new JSONObject();
		json.put("macoffset",mac+"_"+environment.getOffset());
		json.put("statistics_time",simpleDateFormat.format(start_date));
		return json;
	}

	public static JSONObject getJsonEnvTowStr(String mac, EnvironmentTower environment, Long start_date) {

		JSONObject json = new JSONObject();
		json.put("macoffset",mac+"_"+environment.getOffset());
		json.put("statistics_time",simpleDateFormat.format(start_date));
		return json;

	}
}
